<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        // 定义防抖函数
        const debounce = (func,wait) => {
            let timerId = null

            return (...rest) => {
                clearTimeout(timerId)

                // 获取参数
                const args = rest

                // this指向
                const that = this

                // const newFunc = func.bind(that,args)
                timerId = setTimeout(() => {
                    // func(args)

                    // 形参和实参个数要匹配
                    // func.apply(that,args)

                    // 形参和实参个数不匹配
                    func.call(that,args)

                    // newFunc()
                }, wait);
            }
        }

        // 调用防抖函数,生成一个新的函数
        const bar = debounce(val => {
            console.log(val)
        },500)

        // 调用新的函数
        bar('123','456')
    
    </script>
</body>
</html>